import request from '@/utils/request';
import { getToken } from "@/utils/auth";

export function getMenuTree() {
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysMenu/getMenuTree',
    method: 'get',
    params: {
      "operationId": getToken()
    }
  });
}

export function getMenuPermissions(id) {
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysPermission/getListByPage',
    method: 'post',
    data: {
      "operationId": getToken(),
      "menuCode": id,
      "pageNum": 1,
      "recordNum": 100
    }
  });
}

export function deletePermission(ids) {
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysPermission/deleteByList',
    method: 'post',
    data: {
      operationId: getToken(),
      keyValues: ids
    }
  });
}

export function deleteMenu(ids) {
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysMenu/deleteByList',
    method: 'post',
    data: {
      operationId: getToken(),
      keyValues: ids
    }
  });
}

export function editMenu(data) {
  const postBody = {
    objectId: data.id,
    createUserId: getToken(),
    modificationUserId: getToken(),
    pid: data.pid,
    sort: data.sortCode,
    name: data.name,
    code: data.code,
    description: data.description,
    path: data.path,
    icon: data.icon,
    isEnable: data.isEnable
  };
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysMenu/update',
    method: 'post',
    data: postBody
  });
}

export function createPermission(data, menuId) {
  const postBody = {
    createUserId: getToken(),
    modificationUserId: getToken(),
    name: data.name,
    service: data.serviceCode,
    menuCode: menuId,
    sort: data.sortCode,
    permission: data.permission
  };
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysPermission/create',
    method: 'post',
    data: postBody
  });
}

export function createMenu(data) {
  const postBody = {
    createUserId: getToken(),
    modificationUserId: getToken(),
    pid: data.pid,
    sort: data.sortCode,
    name: data.name,
    code: data.code,
    description: data.description,
    path: data.path,
    icon: data.icon,
    isEnable: true
  };
  return request({
    url: process.env.VUE_APP_SERVICE_NAME + 'api/sysMenu/create',
    method: 'post',
    data: postBody
  });
}
